package com.jhl.seckill.schedule;


import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class SchedulingDemo {

    /**
     * 0秒开始，每3秒执行一次，同时开启异步执行
     * 异步调用，加了@Async之后调用者可以执行其他操作，而异步方法由单独的线程完成
     */
    @Scheduled(cron = "0/3 * * * * *")
//    @Async
    public void print() throws InterruptedException {
//        System.out.println(Thread.currentThread().getId()+"==定时任务执行时间=="+
//                LocalDateTime.now()
//                        .format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        System.out.println("定时任务执行");
        print2();
    }

    public void print2() throws InterruptedException {
        Thread.sleep(5000);
        System.out.println("同步耗时任务执行完毕");
    }
}
